﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////


#include "FamilyNewFileFromDlg.h"
#include "TranslatorManager.h"

#include "EnableCompileWarning_The_LAST_IncludeInCpp.h"

using namespace gfam;

FamilyNewFileFromDlg::FamilyNewFileFromDlg(QWidget* parent)
    : QDialog(parent, Qt::Dialog | Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint)
{
    m_ui.setupUi(this);
    m_ui.gbmp_title->setStyleSheet("QPushButton{color:black;background:rgb(222, 227, 234)}" "QPushButton{ border:none }" "QPushButton::hover{ background:rgb(215,115,115); }""QFrame{border:none;color:black;background-color:rgb(222, 227, 234);}");
    this->setStyleSheet("QDialog{background-color:rgb(247, 249, 250)}" "QDialog{border:1px solid rgb(213, 219, 229);}");

    m_ui.gbmp_title->setContentsMargins(QMargins(10, 0, 0, 0));
    m_ui.gbmp_title->setFixedHeight(26);
    m_ui.gbmp_title->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
    m_ui.gbmp_title->setIconVisible(false);
    m_ui.gbmp_title->setMaxButtonVisible(false);
    m_ui.gbmp_title->setMinButtonVisible(false);
    m_ui.gbmp_title->setText(QString::fromStdWString(GBMP_TR(L"新建方式")));
    this->setProperty("use_gbmp_title", true);

    connect(m_ui.gbmp_title, &GmTitleBar::closeRequested, this, &FamilyNewFileFromDlg::close);
    connect(m_ui.gbmp_title, &GmTitleBar::moveRequested, this, &FamilyNewFileFromDlg::onMoveRequested);
    connect(m_ui.pushButton, SIGNAL(clicked(bool)), this, SLOT(OnFromLocal()));
    connect(m_ui.pushButton_2, SIGNAL(clicked(bool)), this, SLOT(OnFromCloud()));
}

gfam::FamilyNewFileFromDlg::~FamilyNewFileFromDlg()
{
}

NewFileFromType FamilyNewFileFromDlg::GetFromType() const
{
    return m_type;
}

void FamilyNewFileFromDlg::OnFromLocal()
{
    m_type = FromLocal;
    accept();
}

void FamilyNewFileFromDlg::OnFromCloud()
{
    m_type = FromCloud;
    accept();
}

void gfam::FamilyNewFileFromDlg::onMoveRequested(const QPoint & cursorPos, const QPoint & offset)
{
    Q_UNUSED(cursorPos);
    move(pos() + offset);
}